/* Calculate two fractions */
#include <stdio.h>
int main(void)
{
    int num1, denom1, num2, denom2, result_num, result_denom;
    char operator;
    printf("Enter two fractions separated by a plus sign: ");
    scanf("%d/%d %c%d/%d", &num1, &denom1, &operator, &num2, &denom2);
    switch (operator)
    {
    case '+':
        result_num = num1 * denom2 + num2 * denom1;
        result_denom = denom1 * denom2;
        break;
    case '-':
        result_num = num1 * denom2 - num2 * denom1;
        result_denom = denom1 * denom2;
        break;
    case '*':
        result_num = num1 * num2;
        result_denom = denom1 * denom2;
        break;
    case '/':
        result_num = num1 * denom2;
        result_denom = denom1 * num2;
        break;
    }
    /* 计算最大公约数 */
    int m = result_denom, n = result_num;
    if (m < n) {
        m = m + n;
        n = m - n;
        m = m - n;
    }
    while (n != 0) {
        m = m % n;
        m = m + n;
        n = m - n;
        m = m - n;
    }
    if (result_denom / m == 1)
        printf("The result is %d\n", result_num / m);
    else
        printf("The result is %d/%d\n", result_num / m, result_denom / m);
    return 0;
}